package cn.itsource.service.impl;

import cn.itsource.api.RuleFeignClient;
import cn.itsource.pojo.domain.OrderBill;
import cn.itsource.mapper.OrderBillMapper;
import cn.itsource.pojo.vo.OrderBillProportionVo;
import cn.itsource.result.JSONResult;
import cn.itsource.service.IOrderBillService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 * 订单账单表 服务实现类
 * </p>
 *
 * @author lifan
 * @since 2024-09-20
 */
@Service
public class OrderBillServiceImpl extends ServiceImpl<OrderBillMapper, OrderBill> implements IOrderBillService {

    @Autowired
    private RuleFeignClient ruleFeignClient;

    @Override
    public JSONResult getOrderBill(String orderNo) {
        OrderBill one = super.getOne(new LambdaQueryWrapper<OrderBill>()
                .eq(OrderBill::getOrderNo, orderNo));

        //找抽成比例
        // 3 种情况
        // 1.今日是否取消订单;
        // 2.今日是否被投诉;
        // 3.默认平台的抽成比例
        //这里 只需要总比例就行 只赋值去调用 规则取总比例
        JSONResult driverTotalProportion = ruleFeignClient.getDriverTotalProportion();
        //使用openfeign进行远程调用  如果返回方返回时对象 会变成 linkedHashMap
        //使用openfeign进行远程调用  如果返回方返回时小数 会变成 Double
        //使用openfeign进行远程调用  如果返回方返回时整数 会变成 Integer
        Object data = driverTotalProportion.getData();
        OrderBillProportionVo orderBillProportionVo = new OrderBillProportionVo();
        BeanUtils.copyProperties(one,orderBillProportionVo);
        orderBillProportionVo.setProportion(new BigDecimal(data.toString()));
        return JSONResult.success(orderBillProportionVo);
    }
}
